library(tidyverse)
Registered S3 methods overwritten by 'dbplyr':
method from
print.tbl_lazy
print.tbl_sql
── Attaching packages ─────────────────────────────────────────────────── tidyverse 1.3.1 ──
✓ ggplot2 3.3.5 ✓ purrr 0.3.4
✓ tibble 3.1.6 ✓ dplyr 1.0.8
✓ tidyr 1.2.0 ✓ stringr 1.4.0
✓ readr 2.1.2 ✓ forcats 0.5.1
── Conflicts ────────────────────────────────────────────────────── tidyverse_conflicts() ──
x dplyr::filter() masks stats::filter()
x dplyr::lag() masks stats::lag()
library(plotly)
Registered S3 methods overwritten by 'htmltools':
method from
print.html tools:rstudio
print.shiny.tag tools:rstudio
print.shiny.tag.list tools:rstudio
Registered S3 method overwritten by 'htmlwidgets':
method from
print.htmlwidget tools:rstudio
Attaching package: ‘plotly’
The following object is masked from ‘package:ggplot2’:
last_plot
The following object is masked from ‘package:stats’:
filter
The following object is masked from ‘package:graphics’:
layout
# National Parks in California
ca = read_csv("https://raw.githubusercontent.com/ScienceParkStudyGroup/r-lesson-based-on-ohi-data-training/gh-pages/data/ca.csv")
Rows: 789 Columns: 7
── Column specification ────────────────────────────────────────────────────────────────────
Delimiter: ","
chr (5): region, state, code, park_name, type
dbl (2): visitors, year
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
head(ca)
# Acadia National Park
acadia <- read_csv("https://raw.githubusercontent.com/ScienceParkStudyGroup/r-lesson-based-on-ohi-data-training/gh-pages/data/acadia.csv")
Rows: 98 Columns: 7
── Column specification ────────────────────────────────────────────────────────────────────
Delimiter: ","
chr (5): region, state, code, park_name, type
dbl (2): visitors, year
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
head(acadia)
# Southeast US National Parks
se <- read_csv("https://raw.githubusercontent.com/ScienceParkStudyGroup/r-lesson-based-on-ohi-data-training/gh-pages/data/se.csv")
Rows: 453 Columns: 7
── Column specification ────────────────────────────────────────────────────────────────────
Delimiter: ","
chr (5): region, state, code, park_name, type
dbl (2): visitors, year
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
head(se)
# 2016 Visitation for all Pacific West National Parks
visit_16 <- read_csv("https://raw.githubusercontent.com/ScienceParkStudyGroup/r-lesson-based-on-ohi-data-training/gh-pages/data/visit_16.csv")
Rows: 17 Columns: 7
── Column specification ────────────────────────────────────────────────────────────────────
Delimiter: ","
chr (5): region, state, code, park_name, type
dbl (2): visitors, year
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
head(visit_16)
# All Nationally designated sites in Massachusetts
mass <- read_csv("https://raw.githubusercontent.com/ScienceParkStudyGroup/r-lesson-based-on-ohi-data-training/gh-pages/data/mass.csv")
Rows: 13 Columns: 7
── Column specification ────────────────────────────────────────────────────────────────────
Delimiter: ","
chr (5): region, state, code, park_name, type
dbl (2): visitors, year
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
head(mass)
scatter_plot = plot_ly(data=ca, x=~year, y=~visitors,color = ~park_name, type='scatter',mode='markers') %>%
layout(
title= list(text = "<b>Body weight vs Brain weight"),
legend = list(title = list(text ='<b>Animals')),
xaxis = list(title = list(text ='<b>Brain Weight')),
yaxis = list(title = list(text ='<b>Body Weight')))
scatter_plot
Warning in RColorBrewer::brewer.pal(N, "Set2") :
n too large, allowed maximum for palette Set2 is 8
Returning the palette you asked for with that many colors
Warning in RColorBrewer::brewer.pal(N, "Set2") :
n too large, allowed maximum for palette Set2 is 8
Returning the palette you asked for with that many colors
Warning in RColorBrewer::brewer.pal(N, "Set2") :
n too large, allowed maximum for palette Set2 is 8
Returning the palette you asked for with that many colors
Warning in RColorBrewer::brewer.pal(N, "Set2") :
n too large, allowed maximum for palette Set2 is 8
Returning the palette you asked for with that many colors
r_group_barchart = data.table::melt(ca, id.vars='park_name') %>%
plot_ly(x = ~park_name, y = ~value, type = 'bar', name = ~variable, color = ~variable) %>%
layout(
title= list(text = "<b>Total Distribution based on Vore"),
legend = list(title = list(text= '<b>Aniamal Feature')),
xaxis = list(title = list(text ='<b>Vores')),
yaxis = list(title='Count', text='<b>Count'), barmode = 'group')
Warning in data.table::melt(ca, id.vars = "park_name") :
The melt generic in data.table has been passed a spec_tbl_df and will attempt to redirect to the relevant reshape2 method; please note that reshape2 is deprecated, and this redirection is now deprecated as well. To continue using melt methods from reshape2 while both libraries are attached, e.g. melt.list, you can prepend the namespace like reshape2::melt(ca). In the next version, this warning will become an error.
r_group_barchart
df_order = data.frame(table(ca$park_name))
df_order
pie_chart = plot_ly(type='pie', labels=df_order$Var1, values=df_order$Freq,
textinfo='label+percent',insidetextorientation='radial') %>%
layout(
title= list(text = "<b>Order Distributions"),
legend = list(title = list(text= '<b>Order')))
pie_chart
histogram_plot = plot_ly(data = ca, x = ~(log(visitors)), name=~code,type="histogram") %>%
layout(
title= list(text = "<b>Total sleep time of Animals based on Vore"),
legend = list(title = list(text= '<b>Vore')),
xaxis = list(title = list(text ='<b>Visitors')),
yaxis = list(title = list(text ='<b>Count')))
histogram_plot
df_vore = data.frame(table(ca$code))
df_vore
donut_chart = plot_ly(labels=df_vore$Var1, values=df_vore$Freq,
textinfo='label+percent') %>%
add_pie(hole = 0.6) %>%
layout(
title= list(text = "<b>Order Distributions"),
legend = list(title = list(text= '<b>Order')))
donut_chart
library(gganimate)
library(gifski)
#scatter_plot_animate = ggplot(data=ca, aes(year, visitors)) + geom_point() +
# transition_states(park_name)
#animate(scatter_plot_animate, renderer = gifski_renderer())
## filtering out only 'CHIS', 'DEVA' AND 'JOTR' Park_code
d = ca %>%
filter(code%in%c('CHIS', 'DEVA', 'JOTR'))
d
line_plot = ggplot(d, aes(x=year, y=visitors, group=code, color=code)) +
geom_line() + geom_point() +
transition_reveal(year)
animate(line_plot, width=300, height=300, renderer = gifski_renderer())
Rendering [=>-------------------------------------------------------] at 13 fps ~ eta: 8s
Rendering [=>-------------------------------------------------------] at 12 fps ~ eta: 8s
Rendering [==>------------------------------------------------------] at 12 fps ~ eta: 8s
Rendering [===>-----------------------------------------------------] at 11 fps ~ eta: 8s
Rendering [====>----------------------------------------------------] at 12 fps ~ eta: 8s
Rendering [=====>---------------------------------------------------] at 11 fps ~ eta: 8s
Rendering [=====>--------------------------------------------------] at 9.7 fps ~ eta: 9s
Rendering [======>-------------------------------------------------] at 9.9 fps ~ eta: 9s
Rendering [======>--------------------------------------------------] at 10 fps ~ eta: 9s
Rendering [=======>------------------------------------------------] at 9.5 fps ~ eta: 9s
Rendering [=======>------------------------------------------------] at 9.6 fps ~ eta: 9s
Rendering [========>-----------------------------------------------] at 9.8 fps ~ eta: 9s
Rendering [=========>----------------------------------------------] at 9.4 fps ~ eta: 9s
Rendering [=========>----------------------------------------------] at 9.5 fps ~ eta: 9s
Rendering [==========>---------------------------------------------] at 9.6 fps ~ eta: 8s
Rendering [==========>---------------------------------------------] at 9.3 fps ~ eta: 9s
Rendering [===========>--------------------------------------------] at 9.4 fps ~ eta: 8s
Rendering [============>-------------------------------------------] at 9.2 fps ~ eta: 8s
Rendering [============>-------------------------------------------] at 9.3 fps ~ eta: 8s
Rendering [=============>------------------------------------------] at 9.4 fps ~ eta: 8s
Rendering [==============>-----------------------------------------] at 9.5 fps ~ eta: 8s
Rendering [===============>----------------------------------------] at 9.6 fps ~ eta: 7s
Rendering [===============>----------------------------------------] at 9.7 fps ~ eta: 7s
Rendering [================>---------------------------------------] at 9.8 fps ~ eta: 7s
Rendering [=================>--------------------------------------] at 9.9 fps ~ eta: 7s
Rendering [==================>--------------------------------------] at 10 fps ~ eta: 7s
Rendering [===================>-------------------------------------] at 10 fps ~ eta: 6s
Rendering [====================>------------------------------------] at 10 fps ~ eta: 6s
Rendering [=====================>-----------------------------------] at 10 fps ~ eta: 6s
Rendering [======================>----------------------------------] at 10 fps ~ eta: 6s
Rendering [=======================>---------------------------------] at 10 fps ~ eta: 6s
Rendering [========================>--------------------------------] at 10 fps ~ eta: 5s
Rendering [========================>--------------------------------] at 11 fps ~ eta: 5s
Rendering [=========================>-------------------------------] at 11 fps ~ eta: 5s
Rendering [==========================>------------------------------] at 11 fps ~ eta: 5s
Rendering [===========================>-----------------------------] at 11 fps ~ eta: 5s
Rendering [============================>----------------------------] at 11 fps ~ eta: 5s
Rendering [=============================>---------------------------] at 11 fps ~ eta: 4s
Rendering [==============================>--------------------------] at 11 fps ~ eta: 4s
Rendering [===============================>-------------------------] at 11 fps ~ eta: 4s
Rendering [================================>------------------------] at 11 fps ~ eta: 4s
Rendering [=================================>-----------------------] at 11 fps ~ eta: 4s
Rendering [==================================>----------------------] at 11 fps ~ eta: 4s
Rendering [==================================>----------------------] at 11 fps ~ eta: 3s
Rendering [===================================>---------------------] at 11 fps ~ eta: 3s
Rendering [====================================>--------------------] at 11 fps ~ eta: 3s
Rendering [=====================================>-------------------] at 11 fps ~ eta: 3s
Rendering [======================================>------------------] at 11 fps ~ eta: 3s
Rendering [=======================================>-----------------] at 11 fps ~ eta: 3s
Rendering [========================================>----------------] at 11 fps ~ eta: 3s
Rendering [=========================================>---------------] at 11 fps ~ eta: 2s
Rendering [==========================================>--------------] at 11 fps ~ eta: 2s
Rendering [===========================================>-------------] at 11 fps ~ eta: 2s
Rendering [============================================>------------] at 11 fps ~ eta: 2s
Rendering [=============================================>-----------] at 11 fps ~ eta: 2s
Rendering [==============================================>----------] at 11 fps ~ eta: 2s
Rendering [===============================================>---------] at 11 fps ~ eta: 1s
Rendering [================================================>--------] at 11 fps ~ eta: 1s
Rendering [=================================================>-------] at 11 fps ~ eta: 1s
Rendering [==================================================>------] at 11 fps ~ eta: 1s
Rendering [===================================================>-----] at 11 fps ~ eta: 1s
Rendering [====================================================>----] at 11 fps ~ eta: 1s
Rendering [=====================================================>---] at 11 fps ~ eta: 1s
Rendering [=====================================================>---] at 11 fps ~ eta: 0s
Rendering [======================================================>--] at 11 fps ~ eta: 0s
Rendering [=======================================================>-] at 11 fps ~ eta: 0s
Rendering [=========================================================] at 11 fps ~ eta: 0s
Inserting image 1 at 0.00s (1%)...
Inserting image 2 at 0.10s (2%)...
Inserting image 3 at 0.20s (3%)...
Inserting image 4 at 0.30s (4%)...
Inserting image 5 at 0.40s (5%)...
Inserting image 6 at 0.50s (6%)...
Inserting image 7 at 0.60s (7%)...
Inserting image 8 at 0.70s (8%)...
Inserting image 9 at 0.80s (9%)...
Inserting image 10 at 0.90s (10%)...
Inserting image 11 at 1.00s (11%)...
Inserting image 12 at 1.10s (12%)...
Inserting image 13 at 1.20s (13%)...
Inserting image 14 at 1.30s (14%)...
Inserting image 15 at 1.40s (15%)...
Inserting image 16 at 1.50s (16%)...
Inserting image 17 at 1.60s (17%)...
Inserting image 18 at 1.70s (18%)...
Inserting image 19 at 1.80s (19%)...
Inserting image 20 at 1.90s (20%)...
Inserting image 21 at 2.00s (21%)...
Inserting image 22 at 2.10s (22%)...
Inserting image 23 at 2.20s (23%)...
Inserting image 24 at 2.30s (24%)...
Inserting image 25 at 2.40s (25%)...
Inserting image 26 at 2.50s (26%)...
Inserting image 27 at 2.60s (27%)...
Inserting image 28 at 2.70s (28%)...
Inserting image 29 at 2.80s (29%)...
Inserting image 30 at 2.90s (30%)...
Inserting image 31 at 3.00s (31%)...
Inserting image 32 at 3.10s (32%)...
Inserting image 33 at 3.20s (33%)...
Inserting image 34 at 3.30s (34%)...
Inserting image 35 at 3.40s (35%)...
Inserting image 36 at 3.50s (36%)...
Inserting image 37 at 3.60s (37%)...
Inserting image 38 at 3.70s (38%)...
Inserting image 39 at 3.80s (39%)...
Inserting image 40 at 3.90s (40%)...
Inserting image 41 at 4.00s (41%)...
Inserting image 42 at 4.10s (42%)...
Inserting image 43 at 4.20s (43%)...
Inserting image 44 at 4.30s (44%)...
Inserting image 45 at 4.40s (45%)...
Inserting image 46 at 4.50s (46%)...
Inserting image 47 at 4.60s (47%)...
Inserting image 48 at 4.70s (48%)...
Inserting image 49 at 4.80s (49%)...
Inserting image 50 at 4.90s (50%)...
Inserting image 51 at 5.00s (51%)...
Inserting image 52 at 5.10s (52%)...
Inserting image 53 at 5.20s (53%)...
Inserting image 54 at 5.30s (54%)...
Inserting image 55 at 5.40s (55%)...
Inserting image 56 at 5.50s (56%)...
Inserting image 57 at 5.60s (57%)...
Inserting image 58 at 5.70s (58%)...
Inserting image 59 at 5.80s (59%)...
Inserting image 60 at 5.90s (60%)...
Inserting image 61 at 6.00s (61%)...
Inserting image 62 at 6.10s (62%)...
Inserting image 63 at 6.20s (63%)...
Inserting image 64 at 6.30s (64%)...
Inserting image 65 at 6.40s (65%)...
Inserting image 66 at 6.50s (66%)...
Inserting image 67 at 6.60s (67%)...
Inserting image 68 at 6.70s (68%)...
Inserting image 69 at 6.80s (69%)...
Inserting image 70 at 6.90s (70%)...
Inserting image 71 at 7.00s (71%)...
Inserting image 72 at 7.10s (72%)...
Inserting image 73 at 7.20s (73%)...
Inserting image 74 at 7.30s (74%)...
Inserting image 75 at 7.40s (75%)...
Inserting image 76 at 7.50s (76%)...
Inserting image 77 at 7.60s (77%)...
Inserting image 78 at 7.70s (78%)...
Inserting image 79 at 7.80s (79%)...
Inserting image 80 at 7.90s (80%)...
Inserting image 81 at 8.00s (81%)...
Inserting image 82 at 8.10s (82%)...
Inserting image 83 at 8.20s (83%)...
Inserting image 84 at 8.30s (84%)...
Inserting image 85 at 8.40s (85%)...
Inserting image 86 at 8.50s (86%)...
Inserting image 87 at 8.60s (87%)...
Inserting image 88 at 8.70s (88%)...
Inserting image 89 at 8.80s (89%)...
Inserting image 90 at 8.90s (90%)...
Inserting image 91 at 9.00s (91%)...
Inserting image 92 at 9.10s (92%)...
Inserting image 93 at 9.20s (93%)...
Inserting image 94 at 9.30s (94%)...
Inserting image 95 at 9.40s (95%)...
Inserting image 96 at 9.50s (96%)...
Inserting image 97 at 9.60s (97%)...
Inserting image 98 at 9.70s (98%)...
Inserting image 99 at 9.80s (99%)...
Inserting image 100 at 9.90s (100%)...
Encoding to gif... done!
Visitors started to visit Channel Islands National Park in 1960’s (latest among) has very low visitors till date. Joshua Tree National Park has a continuous growth of visitors without a big drop. Death Valley National Park has a continuous growth of visitors in 2010’s and a gradual pick-up.